<template>
  <a-card :bordered="false" :class="'cust-erp-sub-tab'" style="padding: 10px">
    <!-- 查询区域 -->
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQueryEnter">
        <a-row :gutter="24">
          <a-col :xl="8" :lg="7" :md="8" :sm="24">
            <a-form-item label="工单ID">
              <a-input placeholder="请输入工单ID" v-model="queryParam.woId"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="8" :lg="7" :md="8" :sm="24">
            <a-form-item label="盒号编码">
              <a-input placeholder="请输入盒号编码" v-model="queryParam.lotNo"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="8" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->
    <!-- table区域-begin -->
    <div>
      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="recId"
        :scroll="{x:true}"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange,type:'radio'}"
        :customRow="clickThenSelect"
        @change="handleTableChange">
      </a-table>
    </div>
  </a-card>
</template>

<script>

import { JeecgListMixin } from '@/mixins/JeecgListMixin'

export default {
  name: 'PackageMiddleBoxList',
  mixins: [JeecgListMixin],
  components: {},
  props: {
    fatherCode: {
      type: String,
      default: '',
      required: false
    },
    woId: {
      type: String,
      default: '',
      required: false
    }

  },
  watch: {
    fatherCode: {
      immediate: true,
      handler(val) {
        if (!this.fatherCode) {
          this.clearList()
        } else {
          this.queryParam['boxNo'] = this.fatherCode
          this.queryParam['woId'] = this.woId
          this.queryParam['unit'] = '0'
          this.loadData(1)
        }
      }
    }
  },
  data() {
    return {
      description: '工单BOM',
      disableMixinCreated: true,
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          fixed: 'left',
          width: 60,
          align: 'center',
          customRender: function(t, r, index) {
            return parseInt(index) + 1
          }
        },
        {
          title: '盒码',
          align: 'center',
          dataIndex: 'lotno'
        },
        {
          title: '批次数量',
          align: 'center',
          dataIndex: 'qty'
        },
        {
          title: '当前批次数量',
          align: 'center',
          dataIndex: 'qtyCur'
        },
        {
          title: '状态',
          align: 'center',
          dataIndex: 'status'
        },
        {
          title: '类型',
          align: 'center',
          dataIndex: 'unit'
        },
        {
          title: '重量',
          align: 'center',
          dataIndex: 'weight'
        },
        {
          title: '更新时间',
          align: 'center',
          sorter: true,
          dataIndex: 'ctime'
        }
        // {
        //   title: '操作',
        //   dataIndex: 'action',
        //   align: 'center',
        //   fixed: 'right',
        //   width: 147,
        //   scopedSlots: {customRender: 'action'}
        // }
      ],
      url: {
        list: '/trace/packageTrace/listBoxPackage'
      },
      dictOptions: {}
    }
  },
  created() {
  },
  computed: {
    importExcelUrl() {
      return `${window._CONFIG['domianURL']}/${this.url.importUrl}/${this.mainId}`
    }
  },
  methods: {
    searchReset() {
      this.queryParam = {
        unit: '0'
      }
      this.loadData(1)
    },
    searchQueryEnter() {
      if (this.queryParam.lotNo.indexOf('|') >= 0) {
        let arr = this.queryParam.lotNo.split('|')
        this.queryParam.woId = arr[2]
        this.queryParam.lotNo = arr[0] + '|' + arr[4] + '|' + arr[5]
      }
      this.loadData(1)
      this.selectedRowKeys = []
      this.selectionRows = []
    },
    clickThenSelect(record) {
      return {
        on: {
          click: () => {
            this.onSelectChange(record.recId.split(','), [record])
            this.$emit('itemClick', record)
          }
        }
      }
    },
    clearList() {
      this.dataSource = []
      this.selectedRowKeys = []
      this.ipagination.current = 1
    }

  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>
